package com.aiti.lulian.service.impl;

import com.aiti.lulian.dto.ClickDto;
import com.aiti.lulian.entity.LuLianRecruitment;
import com.aiti.lulian.entity.LuLianSourcingDemand;
import com.aiti.lulian.entity.LuLianSupplierInquiryOrder;
import com.aiti.lulian.service.IClickService;
import com.aiti.lulian.service.ILuLianRecruitmentService;
import com.aiti.lulian.service.ILuLianSourcingDemandService;
import com.aiti.lulian.service.ILuLianSupplierInquiryOrderService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ClickServiceImpl implements IClickService {

    @Autowired
    private ILuLianSourcingDemandService luLianSourcingDemandService;

    @Autowired
    private ILuLianSupplierInquiryOrderService luLianSupplierInquiryOrderService;

    @Autowired
    private ILuLianRecruitmentService luLianRecruitmentService;

    @Override
    public void increaseClick(ClickDto dto) {
        String module = dto.getModule();
        String id = dto.getId();
        if ("1".equals(module)) {
            // 询价单
            LuLianSourcingDemand sourcingDemand = luLianSourcingDemandService.getById(id);
            luLianSourcingDemandService.update(new LambdaUpdateWrapper<LuLianSourcingDemand>().eq(LuLianSourcingDemand::getBaseId, id).set(LuLianSourcingDemand::getClick, sourcingDemand.getClick() + 1));
        } else if ("2".equals(module)) {
            // 第一类招募单 show_supplier_inquiry_order
            LuLianSupplierInquiryOrder supplierInquiryOrder = luLianSupplierInquiryOrderService.getById(id);
            luLianSupplierInquiryOrderService.update(new LambdaUpdateWrapper<LuLianSupplierInquiryOrder>().eq(LuLianSupplierInquiryOrder::getBaseId, id).set(LuLianSupplierInquiryOrder::getClick, supplierInquiryOrder.getClick() + 1));
        } else if ("3".equals(module)) {
            // 第二类招募单 show_recruitment
            LuLianRecruitment recruitment = luLianRecruitmentService.getById(id);
            luLianRecruitmentService.update(new LambdaUpdateWrapper<LuLianRecruitment>().eq(LuLianRecruitment::getBaseId, id).set(LuLianRecruitment::getClick, recruitment.getClick() + 1));
        }
    }
}